<template>
  <div>
    <Searchbar>
      <el-input @change="getList" v-model="search.userid" placeholder="请输入用户ID"></el-input>
      <el-input @change="getList" v-model="search.username" placeholder="请输入用户名"></el-input>
      <!-- <el-autocomplete
        class="inline-input"
        v-model="selectedSchool"
        :fetch-suggestions="querySchool"
        placeholder="请输入学校名称"
        @select="selectSchool"
      ></el-autocomplete> -->
      <el-select @change="onStatusChange" v-model="search.status" placeholder="请选择用户状态">
        <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-select @change="onJob_titleChange" v-model="search.job_title" placeholder="请选择职称">
        <el-option
          v-for="item in job_titles"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        ></el-option>
      </el-select>
      <el-button class="search-btn" @click="getList" type="primary">查询</el-button>
      <el-button class="search-btn" @click="resetSearch" type="primary">重置</el-button>
    </Searchbar>
    <TableBar>
      <el-button @click="onShowCreate" type="primary" icon="el-icon-plus">新建</el-button>
      <el-button @click="onShowUpload" icon="el-icon-upload">批量上传</el-button>
      <el-button @click="onMulForbidden" icon="el-icon-lock">批量封停</el-button>
      <el-button @click="onMulEnable" icon="el-icon-unlock">批量启用</el-button>
    </TableBar>
    <el-table :data="tableData" @selection-change="handleSelectionChange" style="width: 100%">
      <el-table-column fixed="left" type="selection" width="55"></el-table-column>
      <el-table-column fixed="left" type="index" label="序号" width="55"></el-table-column>
      <el-table-column prop="userid" label="用户ID" ></el-table-column>
      <el-table-column prop="username" label="用户名" ></el-table-column>
      <el-table-column prop="phone" label="手机号" ></el-table-column>
      <el-table-column prop="school_name" label="学校名称" ></el-table-column>
      <el-table-column prop="job_title" label="职称" ></el-table-column>
      <el-table-column prop="statusLabel" label="状态" ></el-table-column>
      <el-table-column prop="create_time" label="创建时间" ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            @click="onShowDetail(scope.row)"
            size="small"
            class="text-button"
          >查看</el-button>

          <el-button @click="onShowEdit(scope.row)" size="small" class="text-default">编辑</el-button>

          <el-button
            @click="onForbidden(scope.row)"
            size="small"
            :class="scope.row.status == 1 ? 'text-warning' : 'text-button'"
          >{{scope.row.status == 1 ? '封停' : '启用'}}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, sizes, jumper"
      @current-change="handleCurrentChange"
      @size-change=handleSizeChange
      :current-page.sync="search.page"
      :page-sizes="page_sizes"
      :page-size="search.page_size"
      :total="total"
    ></el-pagination>
    <EditExpert @afterSubmit="getList" @onClose="onHideEdit" :obj="editRow" :show="showEdit" />

    <MulUpload :temp="3" :type="5" @onClose="onHideUpload" :show="showUpload" />
  </div>
</template>
<script>
import EditExpert from "@/modals/EditExpert";
import MulUpload from "@/components/MulUpload";
import CreateFilter from "@/mixins/CreateFilter";
import showEditMixin from "@/mixins/showEditMixin";
import uploadMixin from "@/mixins/uploadMixin";
import pageMixin from "@/mixins/pageMixin";
import blockMixin from "@/mixins/blockMixin";
import { expertModel } from "@/api/admin_models";
import Searchbar from "@/components/Searchbar";
import TableBar from "@/components/TableBar";
export default {
  mixins: [CreateFilter, showEditMixin, uploadMixin, pageMixin, blockMixin],
  components: { EditExpert, MulUpload, Searchbar, TableBar },
  data() {
    return {
      tableData: [],
      total: 0,
      search: {
        userid: null,
        username: null,
        selectedschool_id: null,
        status: null,
        job_title: null,
        page: 1,
        page_size: 10
      }
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    batchBlockFun() {
      return expertModel.batchBlock;
    },
    resetSearch() {
      this.search = {
        userid: null,
        username: null,
        selectedschool_id: null,
        status: null,
        job_title: null,
      }
      this.getList() 
    },
    onShowDetail(row) {
      this.$router.push('expert/' + row.userid)
      console.log(row);
    },
    getList() {
      console.log("getList");
      expertModel.list(
        this.search,
        res => {
          this.total = res.total_records;
          this.tableData = res.data.map(v => {
            v.statusLabel = this.statusToLabel(v.status);

            return v;
          });
        },
        err => {
          console.log(err);
        }
      );
    }
  }
};
</script>
<style lang="scss">
</style>